<template>

  <div  class="box">
      <el-table
    :data="tableData"
    style="width: 100%">
    <!-- <el-table-column
      label="日期"
      width="180">
      <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{ scope.row.date }}</span>
      </template>
    </el-table-column> -->
    <el-table-column
      label="序号"
      >
      <template slot-scope="scope">
            <el-tag size="medium">{{ scope.row.id}}</el-tag>
      </template>
    </el-table-column>
    <el-table-column
      label="名称"
      >
      <template slot-scope="scope">
            <el-tag size="medium">{{ scope.row.name }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column
      label="价格"
      >
      <template slot-scope="scope">
            <el-tag size="medium">{{ scope.row.name }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column
      label="数量"
      >
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handJian(scope.$index, scope.row)">减少</el-button>
            <span>{{scope.row.num}}</span>
            <el-button
          size="mini"
          @click="handJia(scope.$index, scope.row)">增加</el-button>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
           <span></span>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
    </el-table>
    


  </div>

</template>

<script>
import { getHomeData} from '../api/index'
  export default {
    data() {
      return {
        tableData: [{
          id:'1',
          date: '2016-05-02',
          name: '王小虎',
          price:"50",
          address: '上海市普陀区金沙江路 1518 弄',
          num:'10'
        }, {
          id:'2',
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄',
          num:'10'
        }, {
          id:'3',
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄',
          num:'10'
        }, {
          id:'4',
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄',
          num:'10'
        }]
      }
    },
    mounted() {
      let homeArr=[];
      getHomeData().then(res=>{
        res.map(item=>{
          item.data=new Data().toLocaleDateString()
          homeArr.path(item)
          console.log(homeArr)
        })
        console.log(homeArr)
        this.tableData=homeArr
      })
    },
    methods: {  
      
      handleEdit(index, row) {
        console.log(index, row);
      },
      handleDelete(index, row) {
        console.log(index, row);
      },
      handJia(index,row){
        row.num++
      },
      handJian(index,row){
        if(row.num>=1){
         row.num--
        }else{
          row.num=1
        }
        
      }
      // getHomeData({

      // }).then(res=>)
    }
  }
</script>

<style scoped>
.box{
  width:100%
}

</style>
